home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvi2tty / dvi2tty.c < prev    next >
C/C++ Source or Header  |  1995-01-12  |  25KB  |  663 lines

  1. /******************************************************************************
  2.  * Marcel Mol: 1990-03-27  (UUCP: marcel@duteca.tudelft.nl)
  3.  *               Fixed bug that causes the program to hang when it finds a
  4.  *               fontname with an 's' in it not followed by an 'y'.
  5.  *               Thanks to Paul Orgren (orgren@Stars.Reston.Unisys.COM).
  6.  * Marcel Mol: 1990-02-04  (UUCP: marcel@duteca.tudelft.nl)
  7.  *               First attempt to recognize symbol fonts, so bullets (in
  8.  *               itemized lists) are translated to a proper character instead
  9.  *               an awfull ligature.
  10.  *               Version 4.0.
  11.  * Marcel Mol: 1990-02-01  (UUCP: marcel@duteca.tudelft.nl)
  12.  *               Included port to VMS (off Joseph Vasallo and Seppo Rantala)
  13.  *               into latest version. Hope things still work, cannot test it ...
  14.  * Joseph Vasallo & Seppo Rantala: 1989-09-05 (Internet: rantala@tut.FI)
  15.  *         Ported to work under VAX/VMS V4.4 & VAXC V2.4 or higher.
  16.  *         Fixed bugs in using Swedish/Finnish characters.
  17.  * Marcel Mol: 1989-02-14  (UUCP: duteca!marcel)
  18.  *               Fixed check for .dvi extension.
  19.  *               Allowed more ligatures.
  20.  *               Fixed side effect bugs (2 gets as function arguments).
  21.  *               Version 3.2.
  22.  * Marcel Mol: 1989-01-19  (UUCP: duteca!marcel)
  23.  *               Changed in option handling, no change
  24.  *               in user interface (only the undocumented 
  25.  *               feature -e).
  26.  *               Version 3.1.
  27.  * Marcel Mol: 1989-01-11  (UUCP: duteca!marcel)
  28.  *               Changed some longs to ints.
  29.  *               It now also runs on MSDOS Microsoft C 5.1
  30.  *               New version: 3.0
  31.  * Marcel Mol: 1989-01-03  (UUCP: duteca!marcel)
  32.  *               Fixed a bugs concerning pager programs
  33.  *               and scanning environment variable DVI2TTY.
  34.  * Marcel Mol: 1988-10-25  (UUCP: duteca!marcel)
  35.  *        dvi2tty.c dvi2tty.h dvistuff.c commands.h
  36.  *               Converted program to C.
  37.  *               improved spacing between words/characters.
  38.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-08-15 20:24:31,
  39.  *               Version to be sent to mod.sources ready.
  40.  * New option since last version:
  41.  *   -Fprog      Pipe output to prog. Can be used to get a different
  42.  *               pager than the default.
  43.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-13 21:49:31,
  44.  *   Environment variable DVITTY is read and options can be set from it.
  45.  *   These are the currently implemented options:
  46.  *      -ofile   Write output to file, else write to stdout,
  47.  *               possibly piped through a pager if stdout is a tty.
  48.  *      -plist   Print pages whos TeX-page-number are in list.
  49.  *               List is on the form  1,3:6,8  to choose pages
  50.  *               1,3-6 and 8. TeX-nrs can be negative: -p-1:-4,4
  51.  *      -Plist   Print pages whos sequential number are in list.
  52.  *      -wn      Print the lines with width n characters, default is
  53.  *               80. Wider lines gives better results.
  54.  *      -q       Don't try to pipe to a pager.
  55.  *      -f       Try to pipe to a pager if output is a tty.
  56.  *      -Fname   Specify a pager program.                  
  57.  *               Default of -q and -f is a compile time option, a constant.
  58.  *      -l       Write '^L' instead of formfeed between pages.
  59.  *      -u       Don't try to find Scandinavian characters (they will
  60.  *               print as a:s and o:s if this option is choosen).
  61.  *      -s       Scandinavian characters printed as }{|][\.
  62.  *               Default of -s and -u is a compile time option, a constant.
  63.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-10 18:51:03,
  64.  *   Argument parsing, and random access functions (external, in C)
  65.  *   and other OS-dependent stuff (in C). Removed private 'pager' &
  66.  *   tries to pipe through PAGER (environment var) or, if PAGER not
  67.  *   defined, /usr/ucb/more. Some changes for efficency.
  68.  * bogart:/usr/alla/svante/dvitty/dvitty.p  1985-07-15 20:51:00,
  69.  *   The code for processing dvi-files running on UNIX (UCB-Pascal)
  70.  *   but no argument parsing.
  71.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.140, 30-Mar-85 05:43:56,
  72.  *   Edit: Svante Lindahl
  73.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.136, 15-Jan-85 13:52:59,
  74.  *   Edit: Svante Lindahl, final Twenex version !!!??
  75.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.121, 14-Jan-85 03:10:22,
  76.  *   Edit: Svante Lindahl, cleaned up and fixed a lot of little things
  77.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.25, 15-Dec-84 05:29:56,
  78.  *   Edit: Svante Lindahl, COMND-interface, including command line scanning
  79.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.23, 10-Dec-84 21:24:41,
  80.  *   Edit: Svante Lindahl, added command line scanning with Rscan-JSYS
  81.  * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.48,  8-Oct-84 13:26:30,
  82.  *  Edit: Svante Lindahl, fixed switch-parsing, destroyed by earlier patches
  83.  * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.45, 29-Sep-84 18:29:53,
  84.  *  Edit: Svante Lindahl
  85.  *
  86.  * dvitty - get an ascii representation of a dvi-file, suitable for ttys
  87.  *
  88.  * This program, and any documentation for it, is copyrighted by Svante
  89.  * Lindahl. It may be copied for non-commercial use only, provided that
  90.  * any and all copyright notices are preserved.
  91.  *
  92.  * Please report any bugs and/or fixes to:
  93.  *
  94.  * UUCP: {seismo,mcvax,cernvax,diku,ukc,unido}!enea!ttds!zap
  95.  * ARPA: enea!ttds!zap@seismo.CSS.GOV
  96.  *  or   Svante_Lindahl_NADA%QZCOM.MAILNET@MIT-MULTICS.ARPA
  97.  * EAN:  zap@cs.kth.sunet
  98.  */
  99.  
  100.  
  101. #include "dvi2tty.h"
  102. #if defined(VMS)
  103. #include unixio
  104. #endif
  105.  
  106.     /*-----------------------------------------------------------------------*/
  107.     /* The following constants may be toggled before compilation to          */
  108.     /* customize the default behaviour of the program for your site.         */
  109.     /* Whichever their settings are, the defaults can be overridden at       */
  110.     /* runtime.                                                              */
  111.     /*-----------------------------------------------------------------------*/
  112.  
  113. #define DEFSCAND    FALSE     /* default is Scandinavian, toggle this if you */
  114.                               /* don't have terminals with Scand. nat. chars */
  115. #define WANTPAGER   TRUE      /* default: try to pipe through a pager (like  */
  116.                               /* more) if stdout is tty and no -o switch     */
  117. #define DEFPAGER    "/usr/bin/pg"   /* CHANGE TO YOUR LOCAL PAGER            */
  118.  
  119.     /*------------------ end of customization constants ---------------------*/
  120.  
  121. #define MAXLEN          100    /* size of char-arrays for strings            */
  122. #if defined(MSDOS) || defined(VMS)
  123. #define OPTSET      "wepPousl"   /* legal options                            */
  124. #define OPTWARG     "wepPo"      /* options with argument                    */
  125. #else
  126. #define OPTSET      "wepPousqlfF"/* legal options                            */
  127. #define OPTWARG     "wepPoF"     /* options with argument                    */
  128. #endif
  129.  
  130. /*
  131.  * USAGE CODES
  132.  */
  133.  
  134. #define wrnge  1                /* width switch arg out of range     */
  135. #define ign    2                /* ignore cause, print 'Usage:..'    */
  136. #define nan    3                /* not a number where one expected   */
  137. #define gae    4                /* garbage at end                    */
  138. #define bdlst  5                /* bad page-numberlist               */
  139. #define onef   6                /* only one dvifile allowed          */
  140. #define bdopt  7                /* bad option                        */
  141. #define onepp  8                /* only one page list allowed        */
  142. #define noarg  9                /* argument expected                 */
  143.  
  144. char *dvi2tty = "@(#) dvi2tty.c  4.1 27/03/90 M.J.E. Mol (c) 1989, 1990";
  145.  
  146. /*---------------------------------------------------------------------------*/
  147.  
  148. printlisttype * currentpage;    /* current page to print                     */
  149. printlisttype * firstpage;      /* first page selected                       */
  150. printlisttype * lastpage;       /* last page selected                        */
  151.  
  152. FILE *          DVIfile;
  153. FILE *          output;
  154. bool            outputtofile;   /* tells if output goes to file or stdout    */
  155. int             ttywidth;       /* max nr of chars per printed line          */
  156. int             espace;         /* to fake calcs with ttywidth               */
  157.  
  158. long            foo;            /* utility variable, "register"              */
  159. #if !defined(MSDOS) && !defined(VMS)
  160. bool            pager;          /* tells if output is piped to a pager       */
  161. char  *         path;           /* name of the pager to run                  */
  162. #endif
  163. char  *         progname;       /* our name                                  */
  164. int             Argc;
  165. char **         Argv;
  166. char            DVIfilename[MAXLEN];
  167. char *          OUTfilename;
  168. char            optch;          /* for option handling                       */
  169.  
  170. /*---------------------------------------------------------------------------*/
  171.  
  172. #if defined(MSDOS)
  173. void    main      (int, char **); 
  174. void    setoption (char *);
  175. void    getargs   (void);
  176. void    getpages  (int, char *);
  177. void    plcnxt    (int);
  178. void    getfname   (char *);
  179. int     getinteger(int *, int *, char *);
  180. void    usage     (int);
  181. #else
  182. char *  getenv    ();
  183. FILE *  popen     ();
  184.  
  185. void    main      (); 
  186. void    setoption ();
  187. void    getargs   ();
  188. void    getpages  ();
  189. void    plcnxt    ();
  190. void    getfname   ();
  191. int     getinteger();
  192. void    usage     ();
  193. #endif
  194.  
  195.  
  196. /****************************************************************************/
  197. /*                                                                          */
  198. /*                                 M A I N                                  */
  199. /*                                                                          */
  200. /****************************************************************************/
  201.  
  202. void main(argc, argv)
  203. int argc;
  204. char ** argv;
  205. {
  206.  
  207.     progname = *argv;
  208.     Argc = argc;
  209.     Argv = argv;
  210.  
  211.     getargs();                              /* read command line arguments   */
  212. #if defined(MSDOS)
  213.     if ((DVIfile = fopen(DVIfilename, "rb")) == NULL)
  214. #else
  215. #if defined(VMS)
  216.     if ((DVIfile = fopen(DVIfilename, "r","ctx=rec")) == NULL)
  217. #else
  218.     if ((DVIfile = fopen(DVIfilename, "r")) == NULL)
  219. #endif
  220. #endif
  221.         errorexit(filop);                   /* can't open dvifile            */
  222.  
  223.     if (outputtofile) {                     /* open the outfile, if needed   */
  224.         if ((output = fopen(OUTfilename, "w")) == NULL)
  225.             errorexit(filcr);
  226. #if !defined(MSDOS) && !defined(VMS)
  227.         pager = FALSE;
  228. #endif
  229.     }
  230.     else {
  231.         output = stdout;
  232. #if !defined(MSDOS) && !defined(VMS)
  233.         if (isatty(fileno(output)) && pager) {   /* try to pipe to a pager   */
  234.             if ((output = popen(path, "w")) == NULL) /* get pipe to pager    */
  235.                 errorexit(pipcr);                /* make output to output    */
  236.         }
  237.         else
  238.             pager = FALSE;
  239. #endif
  240.     }
  241.  
  242.     dvimain();
  243.  
  244. #if !defined(MSDOS) && !defined(VMS)
  245.     if (pager)
  246.         pclose(output);                     /* close pipe to pager            */
  247. #endif
  248.  
  249.     exit(0);
  250.  
  251. } /* main */
  252.  
  253. /*----------------------------------------------------------------------------*/
  254.  
  255. void setoption(optarg)
  256. char *optarg;
  257. {
  258.     int j = 0;
  259.     int ret;
  260.    
  261.     while (strchr(OPTSET, optch) != NULL) {
  262.         switch (optch) {
  263. #if !defined(MSDOS) && !defined(VMS)
  264.         case 'q' : pager = FALSE; break;
  265.         case 'f' : pager = TRUE; break;
  266. #endif
  267.         case 'l' : noffd = TRUE; break;
  268.         case 's' : scascii = TRUE; break;
  269.         case 'u' : scascii = FALSE; break;
  270.             case 'P' :
  271.                sequenceon = TRUE;     /* fall through */
  272.             case 'p' :
  273.                        if (pageswitchon)
  274.                            usage(onepp);
  275.                        getpages(j, optarg);
  276.                        break;
  277.             case 'w' :
  278.                if (getinteger(&ttywidth, &j, optarg))
  279.                            usage(nan);
  280.                        if (optarg[j] != '\0') 
  281.                            usage(gae);
  282.                        if ((ttywidth < 16) || (ttywidth > 132))
  283.                            usage(wrnge);
  284.                        break;
  285.             case 'e' :
  286.                if (getinteger(&espace, &j, optarg))
  287.                            usage(nan);
  288.                        if (optarg[j] != '\0') 
  289.                            usage(gae);
  290.                        break;
  291.             case 'o' :
  292.                        OUTfilename = optarg;
  293.                outputtofile = TRUE;
  294.                        j = strlen(optarg);
  295.                        break;
  296. #if !defined(MSDOS) && !defined(VMS)
  297.             case 'F' :
  298.                        pager = TRUE;
  299.                        path = optarg;
  300.                        j = strlen(optarg);
  301.                        break;
  302. #endif
  303.             default  : 
  304.                        usage(bdopt);
  305.         }
  306.         if ((optch = optarg[j]) == '\0')
  307.             break;
  308.         j++;
  309.         if ((strchr(OPTWARG, optch) != NULL) && (optarg[j]='\0')) {
  310.                 if (--Argc <= 0)
  311.                     usage(noarg);
  312.                 optarg = *++Argv;
  313.                 j = 0;
  314.             }
  315.     }
  316. } /* setoption */
  317.  
  318. /*----------------------------------------------------------------------------*/
  319.  
  320. void getargs()
  321. {
  322.     char *str, *envp;
  323.     bool DVIfound;                      /* if a dvi filename found           */
  324.  
  325.     if (Argc <= 1)
  326.         usage(ign);
  327.  
  328.     pageswitchon = FALSE;       /* show all pages                            */
  329.     sequenceon   = FALSE;       /* selected pages are TeX-numbered           */
  330.     outputtofile = FALSE;       /* write to stdout                           */
  331. #if !defined(MSDOS) && !defined(VMS)
  332.     pager        = WANTPAGER;   /* want paging, compile time option          */
  333. #endif
  334.     noffd        = FALSE;       /* print formfeed between pages              */
  335.     scascii      = DEFSCAND;    /* scandinavian, compile time option         */
  336.     ttywidth     = 80;          /* default terminal width                    */
  337.     espace       = 0;           /* to fake ttywith calcs                     */
  338.     DVIfound     = FALSE;
  339.  
  340. #if !defined(MSDOS) && !defined(VMS)
  341.     if ((path = getenv("PAGER")) == NULL)   /* find default pathname of page */
  342.             path = DEFPAGER;             /* program in case paging is wanted */
  343. #endif
  344.  
  345.     if ((envp = getenv("DVI2TTY")) != NULL) {
  346.         while (*envp == ' ')
  347.              envp++;
  348.         while (*envp) {                     /* environment var args          */
  349.             if (strchr(OPTSET, optch = *envp++) != NULL) {
  350.                 /*
  351.                  * we always pass one option, and arrange for optarg ourselfves,
  352.                  * so setoption does not mesh up Argv
  353.                  */
  354.                 if (strchr(OPTWARG, optch) != NULL) {
  355.                     while (*envp == ' ') 
  356.                         envp++;
  357.                     if (*envp == '\0')
  358.                         usage(noarg);
  359.                     str = envp;             /* str points to optarg          */
  360.                     while ((*envp != ' ') && (*envp != '\0'))
  361.                         *envp++;            /* set envp just after optarg    */
  362.                     if (*envp != '\0')
  363.                         *envp++ = '\0';     /* end optarg string             */
  364.                 }
  365.                 else
  366.                     str = "";
  367.                 setoption(str);
  368.             }
  369.             else
  370.                 usage(bdopt);
  371.             while (*envp == ' ')
  372.                  envp++;
  373.         }
  374.     }
  375.  
  376.     while (--Argc > 0) {                    /* command line args             */
  377.         str = *++Argv;
  378.         if (*str != '-') {                  /* argument is not an option     */
  379.             if (DVIfound)                   /* only one dvi file allowed     */
  380.                 usage(onef);
  381.             getfname(str);
  382.             DVIfound = TRUE;
  383.         }
  384.         else if (strchr(OPTSET, optch = *++str) != NULL) {
  385.             str++;                      /* point to rest of argument if any  */
  386.             if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) {
  387.                 if (--Argc <= 0)
  388.                     usage(noarg);
  389.                 str = *++Argv;
  390.             }
  391.             setoption(str);
  392.         }
  393.         else
  394.             usage(bdopt);
  395.     }
  396.  
  397.     if (!DVIfound)
  398.         usage(ign);
  399.  
  400. } /* getargs */
  401.  
  402. /*---------------------------------------------------------------------------*/
  403.  
  404. void getpages(j, str)
  405. int j;
  406. char *str;
  407. {
  408.     int i, c;
  409.     int num;
  410.  
  411.     pageswitchon = TRUE;
  412.     firstpage = (printlisttype *) malloc(sizeof(printlisttype));
  413.     firstpage->all = FALSE;
  414.     firstpage->nxt = nil;
  415.     firstpage->pag = 0;
  416.     lastpage = firstpage;
  417.     currentpage = firstpage;
  418.     if (getinteger(&num, &j, str))
  419.         usage(nan);
  420.     plcnxt((int) num);
  421.     while (str[j]) {
  422.         c = str[j];
  423.         if (c == ',' || c == ':') {
  424.             j++;
  425.             if (getinteger(&num, &j, str))
  426.                 usage(nan);
  427.         }
  428.         else
  429.             break;
  430.         if (c == ',')
  431.             plcnxt(num);
  432.         else {
  433.             if (currentpage->pag < 0) {
  434.                 if (num > 0) {
  435.                     currentpage->all = TRUE;
  436.                     plcnxt(num);
  437.                 }
  438.                 else if (num < currentpage->pag)
  439.                     for (i = currentpage->pag - 1; i >= num; i--)
  440.                         plcnxt(i);
  441.                 else
  442.                     usage(bdlst);
  443.             }
  444.             else {
  445.                 if (num < currentpage->pag)
  446.                     usage(bdlst);
  447.                 for (i = currentpage->pag + 1; i <= num; i++)
  448.                     plcnxt(i);
  449.             }
  450.         }
  451.     }
  452.     if ((str[j] != ' ') && (str[j] != NULL)) {
  453.         usage(gae);
  454.     }
  455.     currentpage = firstpage;
  456.  
  457. } /* getpages */
  458.  
  459.  
  460. void plcnxt(pagnr)      /* place page-nr next in list */
  461. int pagnr;
  462. {
  463.     currentpage = lastpage;
  464.     currentpage->pag = pagnr;
  465.     lastpage = (printlisttype *) malloc(sizeof(printlisttype));
  466.     lastpage->all = FALSE;
  467.     lastpage->nxt = nil;
  468.     lastpage->pag = 0;
  469.     currentpage->nxt = lastpage;
  470.  
  471. } /* plcnxt */
  472.  
  473. /*----------------------------------------------------------------------------*/
  474.  
  475. void getfname(str)
  476. char *str;
  477. {
  478.     int   i;
  479.  
  480.     i = strlen(str);
  481.     if (i == 0)
  482.         usage(ign);
  483.     strcpy(DVIfilename, str);
  484.     if (!((i >= 5) && (str[i-1] == 'i') && (str[i-2] == 'v') &&
  485.           (str[i-3] == 'd') && (str[i-4] == '.'))) {
  486.         strcat(DVIfilename, ".dvi");
  487.     }
  488.  
  489. } /* getfname */
  490.  
  491. /*----------------------------------------------------------------------------*/
  492.  
  493. int getinteger(dest, j, str)
  494. int *dest;
  495. int *j;
  496. char *str;
  497. {
  498.     int  cum;
  499.     int  sgn;
  500.     char ch;
  501.  
  502.     ch = str[*j];
  503.     if (ch == '-') {
  504.         sgn = -1;
  505.         ch  = str[++(*j)];
  506.     }
  507.     else
  508.         sgn = 1;
  509.     if ((ch >= '0') && (ch <= '9')) {
  510.         cum = 0;
  511.         while ((ch >= '0') && (ch <= '9')) {
  512.             cum = cum*10 + ch - '0';
  513.             ch = str[++(*j)];
  514.         }
  515.         *dest = sgn * cum;
  516.         return 0;                   /* return ok */
  517.     }
  518.     return 1;                       /* return error */
  519.  
  520. }   /* getinteger */
  521.  
  522. /*----------------------------------------------------------------------------*/
  523.  
  524. void errorexit(errorcode)
  525. int errorcode;
  526. {
  527.  
  528.     fprintf(stderr, "%s: ", progname);
  529.     switch (errorcode) {
  530.         case  illop : fprintf(stderr, "Illegal op-code found: %d\n", opcode);
  531.                       break;
  532.         case  stkof : fprintf(stderr, "Stack overflow\n");
  533.                       break;
  534.         case  stkuf : fprintf(stderr, "Stack underflow\n");
  535.                       break;
  536.         case  stkrq : fprintf(stderr, "Cannot create dvi stack\n");
  537.                       break;
  538.         case  lnerq : fprintf(stderr, "Cannot allocate memory\n");
  539.                       break;
  540.         case  badid : fprintf(stderr, "Id-byte is not correct: %d\n ", opcode);
  541.                       break;
  542.         case  bdsgn : fprintf(stderr, "Bad signature: %d (not 223)\n",
  543.                                       (int) foo);
  544.                       break;
  545.         case  fwsgn : fprintf(stderr, "%d signature bytes (min. 4)\n",
  546.                                       (int) foo);
  547.                       break;
  548.         case  nopre : fprintf(stderr, "Missing preamble\n");
  549.                       break;
  550.         case  nobop : fprintf(stderr, "Missing beginning-of-page command\n");
  551.                       break;
  552.         case  nopp  : fprintf(stderr, "Missing post-post command\n");
  553.                       break;
  554.         case  bdpre : fprintf(stderr, "Preamble occured inside a page\n");
  555.                       break;
  556.         case  bdbop : fprintf(stderr, "BOP-command occured inside a page\n");
  557.                       break;
  558.         case  bdpst : fprintf(stderr, "Postamble occured before end-of-page\n");
  559.                       break;
  560.         case  bdpp  : fprintf(stderr, "Postpost occured before post-command\n");
  561.                       break;
  562.         case  nopst : fprintf(stderr, "Missing postamble\n");
  563.                       break;
  564.         case  illch : fprintf(stderr, "Character code out of range, 0..127\n");
  565.                       break;
  566.         case  filop : fprintf(stderr, "Cannot open dvifile\n");
  567.                       break;
  568.         case  filcr : fprintf(stderr, "Cannot create outfile\n");
  569.                       break;
  570. #if !defined(MSDOS) && !defined(VMS)
  571.         case  pipcr : fprintf(stderr, "Cannot create pipe to pager\n");
  572.                       break;
  573. #endif
  574.         default     : fprintf(stderr, "Unkown error code\n");
  575.                       break;
  576.     };
  577.     if (outputtofile)
  578. #if defined(VMS)
  579.         remove(OUTfilename);
  580. #else
  581.         unlink(OUTfilename);
  582. #endif
  583.     exit(errorcode);
  584.  
  585. }  /* errorexit */
  586.  
  587. /*----------------------------------------------------------------------------*/
  588.  
  589. void usage(uerr)
  590. int uerr;
  591. {
  592.  
  593.     if (uerr != ign) {
  594.         fprintf(stderr,"%s: ", progname);
  595.         switch (uerr) {
  596.             case   ign    : fprintf(stderr, "%s", Copyright);
  597.                             break;
  598.             case   wrnge  : fprintf(stderr, "width arg out of range:16-132");
  599.                             break;
  600.             case   nan    : fprintf(stderr, "numeric argument expected for option %c",
  601.                                             optch);
  602.                             break;
  603.             case   gae    : fprintf(stderr, "garbage in argument for option %c",
  604.                                             optch);
  605.                             break;
  606.             case   bdlst  : fprintf(stderr, "mal-formed list of pagenumbers");
  607.                             break;
  608.             case   onef   : fprintf(stderr, "only one infile argument allowed");
  609.                             break;
  610.             case   noarg  : fprintf(stderr, "option argument expected for option %c",
  611.                                             optch);
  612.                             break;
  613.             case   bdopt  : fprintf(stderr, "bad option %c", optch);
  614.                             break;
  615.             case   onepp  : fprintf(stderr, "only one pagelist allowed");
  616.                             break;
  617.             default       : fprintf(stderr, "unknown usage error");
  618.                             break;
  619.         }
  620.         fprintf(stderr, "\n");
  621.     }
  622.     fprintf(stderr, "Usage: %s [ options ] dvifile[.dvi]\n", progname);
  623.     fprintf(stderr, "Options are:\n");
  624.     fprintf(stderr,
  625.             " -ofile   Write output to file, else write to stdout.\n");
  626.     fprintf(stderr,
  627.             " -plist   Print pages whos TeX-page-number are in list.\n");
  628.     fprintf(stderr,
  629.             " -Plist   Print pages whos sequential number are in list.\n");
  630.     fprintf(stderr,
  631.             " -wn      Print the lines with width n characters, default 80.\n");
  632. #if !defined(MSDOS) && !defined(VMS)
  633.     fprintf(stderr, " -f       Try to pipe to a pager if output is a tty");
  634.     if (WANTPAGER)
  635.         fprintf(stderr, " (default).\n");
  636.     else
  637.         fprintf(stderr, ".\n");
  638.     fprintf(stderr, " -q       Don't try to pipe to a pager");
  639.     if (WANTPAGER)
  640.         fprintf(stderr, ".\n");
  641.     else
  642.         fprintf(stderr, " (default).\n");
  643.     fprintf(stderr, " -Fprog   Pipe output to pager prog.\n");
  644. #endif
  645.     fprintf(stderr,
  646.             " -l       Write ''^L'' instead of formfeed between pages.\n");
  647.     fprintf(stderr,
  648.             " -u       National Swedish/Finnish characters printed as aaoAAO");
  649.     if (DEFSCAND)
  650.         fprintf(stderr, ".\n");
  651.     else
  652.         fprintf(stderr, " (default).\n");
  653.     fprintf(stderr,
  654.             " -s       National Swedish/Finnish characters printed as }{|][\\");
  655.     if (DEFSCAND)
  656.         fprintf(stderr, " (default).\n");
  657.     else
  658.         fprintf(stderr, ".\n");
  659.     exit(uerr);
  660.  
  661. } /* usage */
  662.  
  663.